select 
	{reprint == $补打$:
		$
			cast(o.id as varchar)+ '(票据补打)'			        	
		$,
	 reprint == $正常$:	
		$
		o.id
		$,
        $$
	} id,
	{ entity.findDialect() == $SqlServer$: $CONVERT(varchar(100),o.f_delivery_date,23)$,$TO_CHAR(TO_DATE(o.f_delivery_date, 'yyyy-mm-dd')$} newdata,
	u.f_user_name,		--用户姓名
	u.f_userinfo_id,
	u.f_address,		--用户地址
	o.f_curbalance,     --本期结余
	o.f_balance,		--上期结余
	o.f_tablebase,
	o.f_last_tablebase,
	o.f_pregas,-- 用气量
	o.f_preamount,-- 用气金额
	-- 时间段
	o.f_delaypay,-- 滞纳金
	o.f_payment,
	o.f_collection,		--实收金额
	o.f_operator,		--收费员
	[dbo].[f_num_chn](o.f_collection) f_daxie, --大写实收款 
	isnull(h.f_hand_date,'无') f_hand_date
from t_sellinggas o 
left join (
	select 
		f_sell_id,
		case when MIN(f_hand_date)=MAX(f_hand_date) then 
		 left({ entity.findDialect() == $SqlServer$: $CONVERT(varchar,MAX(f_hand_date),120)$,$TO_CHAR(TO_DATE(MAX(f_hand_date), 'yyyy-mm-dd hh24:mi:ss')$},7) 
		 else 
		 left({ entity.findDialect() == $SqlServer$: $CONVERT(varchar,MIN(f_hand_date),120)$,$TO_CHAR(TO_DATE(MIN(f_hand_date), 'yyyy-mm-dd hh24:mi:ss')$},7)+'至'+
		 left({ entity.findDialect() == $SqlServer$: $CONVERT(varchar,MAX(f_hand_date),120)$,$TO_CHAR(TO_DATE(MAX(f_hand_date), 'yyyy-mm-dd hh24:mi:ss')$},7)
		 end f_hand_date
	from t_handplan where f_meter_state='已抄表' 
	group by f_sell_id
) h on o.id=h.f_sell_id
left join 
t_userinfo u
on o.f_userinfo_id = u.f_userinfo_id
where f_charge_state='有效' and o.id= '{id}'